package com.shop.controller;


import com.shop.entity.SupplierWarehouse;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import com.shop.service.SupplierWarehouseService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * yyt(SupplierWarehouse)表控制层
 *
 * @author makejava
 * @since 2020-11-21 10:12:58
 */
@Validated
@RestController
@RequestMapping("warehouse")
@AllArgsConstructor
public class SupplierWarehouseController {
    /**
     * 服务对象
     */
    private final SupplierWarehouseService supplierWarehouseService;

    /**
     * @param supplierWarehouse
     * @param userId
     * @return {@link Rsp}
     * @author clh
     * @description 添加仓库地址
     * @date 2020/11/27 11:58
     **/
    @PostMapping("insertSelective")
    public Rsp insertSelective(@RequestBody SupplierWarehouse supplierWarehouse,
                               @RequestHeader Integer userId,
                               @RequestHeader Integer supplierId) {

        return supplierWarehouseService.insertSelective(supplierWarehouse, userId, supplierId);
    }

    /**
     * @param supplierWarehouse
     * @param userId
     * @return {@link Rsp}
     * @author clh
     * @description 修改供应商仓库信息
     * @date 2020/11/27 12:24
     **/
    @PostMapping("updateById")
    public Rsp updateById(@RequestBody SupplierWarehouse supplierWarehouse,
                          @RequestHeader Integer userId) {

        return supplierWarehouseService.updateById(supplierWarehouse, userId);
    }

    /**
     * @param supplierWarehouse
     * @return {@link Rsp}
     * @author clh
     * @description 删除
     * @date 2020/11/27 14:22
     **/
    @PostMapping("deleteById")
    public Rsp deleteById(@RequestBody SupplierWarehouse supplierWarehouse) {

        return supplierWarehouseService.deleteById(supplierWarehouse);
    }

    /**
     * @param pageParam
     * @return {@link Rsp}
     * @author clh
     * @description 分页 模糊查询
     * @date 2020/11/27 14:31
     **/
    @PostMapping("searchSomeByPage")
    public Rsp searchSomeByPage(@RequestBody PageParam<SupplierWarehouse> pageParam,
                                @RequestHeader Integer supplierId) {

        return Rsp.success(supplierWarehouseService.searchSomeByPage(pageParam, supplierId));
    }

    /**
     * @param
     * @return {@link Rsp}
     * @author clh
     * @description 查询所有
     * @date 2020/11/28 11:48
     **/
    @PostMapping("queryAll")
    public Rsp queryAll() {

        return supplierWarehouseService.queryAll();
    }

    @GetMapping("getBySupplierId")
    public Rsp getBySupplierId(@RequestHeader("supplierId") Integer id) {
        return supplierWarehouseService.getBySupplierId(id);
    }

    @GetMapping("getDeliveryListByWarehouseId")
    public Rsp getDeliveryListByWarehouseId(Integer id) {
        return Rsp.success(supplierWarehouseService.getDeliveryListByWarehouseId(id));
    }
}
